//////////////////////////////////////////////////////////////////////////
#pragma once


//////////////////////////////////////////////////////////////////////////
#include "Math/Math.hpp"


namespace Math
{
	template< typename T >
	struct Ballistics
	{
		//**********************************************************************
		//	Variables for ballistics are:
		//	R	=	range of entire arc.
		//	T	=	time to peak of arc.
		//	T2	=	time of entire arc.
		//	Ct	=	current time.
		//	G	=	gravity constant.
		//	A	=	angle (in RADIANS) of initial velocity.
		//	P	=	peak height of arc.
		//	V	=	initial velocity.
		//	Vy	=	initial vertical velocity.
		//	Vx	=	initial horizontal velocity.
		//	X	=	position x
		//	Y	=	position y
		//	Ty	=	target y height
		//**********************************************************************

		//
		// Equation derivations.
		//
		static const T			SolveTFromVyG( const T vy, const T g );
		static const T			SolveTFromVxR( const T vx, const T r );
		static const T			SolveT2FromVyG( const T vy, const T g );
		static const T			SolveRFromVAG( const T v, const T a, const T g );
		static const T			SolvePFromVyG( const T vy, const T g );
		static const T			SolveVFromRAG( const T r, const T a, const T g );
		static const T			SolveXFromVxCt( const T vx, const T Ct );
		static const T			SolveYFromVyCtG( const T vy, const T Ct, const T g );
		static void				SolveAFromVRG( const T v, const T r, const T g, T& a0, T& a1 );
		static const bool		SolveAFromVRGTy( const T v, const T r, const T g, const T y, T& a0, T& a1 );

		//
		// Iterative target hit algo.
		//
		static void				SolveAVFromVRGTy( const T v, const T vStep, const T r, const T g, const T y, T& outV, T& a0, T& a1 );

		//**********************************************************************
		//	Rifleman's Rule:
		//		This is an approximation for solving non-level ballistics problems.
		//
		//	The basic equation:  Rh = Rs * cos( A )
		//
		//	Variables:
		//	Rh	=	Range to target horizontally.
		//	Rs	=	Range to target on slant.
		//	A	=	Horizontal angle between source and target.  (Radians)
		//**********************************************************************
		static const T			SolveRhFromRsA( const T rs, const T a );
		static const T			SolveAFromRhRs( const T rh, const T rs );

	private:
		// Not intended for instantiation.
		Ballistics();
	};
}


#include "Detail/Ballistics_Impl.hpp"
